package com.mhuang.cloud.ribbon.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class WebController {

	@Autowired
	RestTemplate client;

    @GetMapping("/queryUserById/{id}")
    @HystrixCommand(fallbackMethod = "queryUserByIdFallback")
    public User queryUserById(@PathVariable Long id) {
        return client.getForObject("http://cloud-mysql/queryUserById/"+id, User.class);
    }
    
    public User queryUserByIdFallback(@PathVariable Long id){
        User user = new User();
        user.setName("服务不可用");
    	return user;
    }
}
